using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rotempco.Core.ORM.Objects;
using Rotempco.Core.ORM.Objects.Stores;

namespace Rotempco.Core.ORM.Managers
{
    public class PagingManager
    {
        #region [ Singleton Constructor ]

        public static PagingManager Instance
        {
            get
            {
                return SingletonStore.Instance.GetInstance<PagingManager>(true);
            }
        }

        #endregion

        public void Page(PagingContainer pagingContainer, Action action)
        {
            try
            {
                // TODO: Disabled paging on all pages
                //PagingStore.Instance.PagingEnabled = true;
                PagingStore.Instance.PagingContainer = pagingContainer;

                action();

                pagingContainer.NumberOfResults = PagingStore.Instance.NumberOfResults;
            }
            finally
            {
                PagingStore.Instance.Clear();
            }
        }
    }
}
